//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:2020/9/11
// @Time:1:09 下午
//
//

#ifndef GEEJOAN_CONNECTION_H
#define GEEJOAN_CONNECTION_H

#include <deque>
#include "boost/asio/ip/tcp.hpp"
#include "BaseComponent.h"

namespace GeeJoan
{
/**
 * @brief 一个tcp 链接一个对应客户端
 */
    class Connection : public std::enable_shared_from_this<Connection>, public BaseComponent
    {

        boost::asio::ip::tcp::socket socket_;

        void do_operations();

        void do_read(boost::system::error_code &ec);

        void call_proc(uint16_t bufflen);

        boost::asio::const_buffer write_buffer_;
        int id;
        std::array<char, NETWORKPACKAGE_MAX_BUFFER_LEN> data_;

     public:

        void init() override;

        void init_complete(Global_Context *context) override;

        virtual ~Connection();

        Connection(boost::asio::ip::tcp::socket socket, int currentid);

        void do_write(const std::string &message, boost::system::error_code &ec);

        void close();

        void start();

    };

}
#endif //GEEJOAN_CONNECTION_H
